#ifndef _AVI_IMAGE_H_
#define _AVI_IMAGE_H_

#include "../sleipner_config.h"
   
#ifdef _PLATFORM_WIN32
#include "./image.h"
#include <windows.h>
#include "Vfw.h"
///////////////////////////////////////////////////////
///	Container for an AVI image.
/// When Tick is called, it will attempt to access the
/// next frame of the animation, and store it into the
/// texture contained.
///////////////////////////////////////////////////////
class AVI : public Image
{
public:
    /**
     * Load the image container.
     *  @param _File    File to load
     */
    virtual bool    Load(const std::string& _File);

    /**
     * Update any book-keeping that needs to be done 
     *  example: updating flipping chain, AVI, etc
     */
    virtual bool    Tick();

    /**
     * Set the current texture to texture stage 
     *  @param _TexStage    Stage to set it to.
     */
    virtual bool    SetTextureStage(unsigned int _TexStage) = 0;
	virtual unsigned int	GetSortVal(){ return 'avi'; };

	float					GetRunTime() const { return float(m_MSPerFrame * m_LastFrame) * 0.001f;};
	bool					GetLoop() { return m_Looping; };
	void					SetLoop(bool b) { m_Looping = b; };

	bool					GetPause() { return m_Paused; };
	void					SetPause(bool b) { m_Paused = b; };

	void					Reset() { m_CurrentFrame = 0; };
	virtual void			Flush();
	virtual void			Recreate();

protected:
    /**
     * Initialize class
     */
					AVI();
    /**
     * Destroy class
     */
	virtual			~AVI();

	virtual void		BlitToTexture() = 0;
	virtual bool 		InitTexture() = 0;
	virtual bool		ShutdownTexture() = 0;

// video code (derived from NeHe's AVI tutorial)
 	AVISTREAMINFO		m_AVIStreamInfo;							/// Pointer To A Structure Containing Stream Info
	PAVISTREAM			m_pAVIStream;								/// Handle To An Open Stream
	PGETFRAME			m_pGetFrame;								/// Pointer To A GetFrame Object
	BITMAPINFOHEADER	m_BMInfo;									/// Header Information For DrawDibDraw Decoding
	long				m_LastFrame;								/// Last Frame Of The Stream
	char*				m_DataA;									/// Pointer To Texture Data
	int					m_MSPerFrame;								/// Will Hold Rough Milliseconds Per Frame
	HDRAWDIB			m_hDrawDIB;								    /// Handle For Our Dib
	HBITMAP				m_hBitmap;									/// Handle To A Device Dependant Bitmap
	HDC					m_hDC;										/// Creates A Compatible Device Context
	unsigned char*		m_ResizeDataA;							    /// Pointer To Our Resized Image

// Current Frame info:
	int					m_CurrentFrame;
	float				m_TimeLeft;
	bool				m_Paused;
	bool                m_Loaded;
    bool                m_Looping;        
	std::string			m_Path, m_File;
};

#else
#include "./image.h"
///////////////////////////////////////////////////////
///	Only Win32 has an active implementation at the moment.
/// All other compilers implement a dummy
///////////////////////////////////////////////////////
class AVI : public Image
{
public:
    bool    		Load(const std::string& _File){ return false; };
    bool    		Tick(){ return false; };
    bool    		SetTextureStage(unsigned int _TexStage) { return false; };
	unsigned int	GetSortVal(){ return 0; };
	float			GetRunTime() const { return 0.0f; };
	bool			GetLoop() { return false; };
	void			SetLoop(bool b) {};
	bool			GetPause() { return false; };
	void			SetPause(bool b) {  };
	void			Reset() {};
	void			Flush(){};
	void			Recreate(){};
protected:
	AVI(){};
	~AVI(){};

};
#endif //_PLATFORM_WIN32



#endif //_AVI_IMAGE_H_